*! version 2.0
* 21 August 2013
* NIDS 
* Reshaping the mortality section of the household questionnaire
	* Data is in wide format in questionnaires.
	* Can be useful for it to be in long format for analysis purposes.

*=====================================================================================================================================
* GLOBALS FOR DATA FILES AND VERSION SUFFIXES

* This do file will reshape Wave 1 and Wave 3 but not Wave 2.

global DataIN "\\137.158.104.21\data\Panel Public Release 2014a\Wave 1\Anon"
global DataOUT "C:\Users\01406074\Desktop"
global VersionIN "W1_Anon_V5.2"
global VersionOUT "merged"
																		
version 12.0													// version of Stata being used, this is needed for the rename command.

*=====================================================================================================================================

* OPENING THE HOUSEHOLD QUESTIONNAIRE, KEEPING RELEVANT VARIABLES AND RESHAPING THE MORTALITY SECTION

use "$DataIN\HHQuestionnaire_$VersionIN.dta", clear					// opening the Household questionnaire data

rename w#_h_* .*
cap keep if  outcome == 1											// keeping households that were successfully interviewed
keep if  mrt24mnth == 1												// keeping households that had a death in the past 24 months 

keep  *hhid mrt*													// keeping the relevant variables
drop mrt24mnth

reshape long  mrtgen mrtr mrtdod_m mrtdod_y mrtage mrtliv  ///
mrtacc mrtpid, i(*hhid) j(mort) string								// reshaping the mortality section to long format
destring mort, replace												// destringing mort number

drop if  mrtgen == .												// dropping empty records
	

* labeling the variables
label var 	mort 		"Number of deceased person"
label var	mrtgen		"c3 - What the deceased's gender?"
label var	mrtr		"c4 - Relationship of deceased to Household Head"
label var	mrtdod_m	"c5_m - Date of death for person 1 - month only"
label var	mrtdod_y	"c5_y - Date of death for person 1 - year only"
label var	mrtage		"c6 - Age in years"
label var 	mrtliv		"c7_1 - Was deceased living here when he/she died?"
label var	mrtacc		"c8 - Cause of death natural?"
label var	mrtpid		"c_pid - deceased's pid"

save "$DataOUT\Mortality_Section_$VersionOUT.dta", replace			// saving out the dataset

* end of do file

*===========================================================================================================================================
